package com.ruoyi.web.controller.tourism;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Hotels;
import com.ruoyi.system.service.IHotelsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 酒店Controller
 *
 * @author Y.C
 * @date 2024-02-21
 */
@Api(tags = "酒店管理")
@RestController
@RequestMapping("/system/hotels")
public class HotelsController extends BaseController
{
    @Autowired
    private IHotelsService hotelsService;

    /**
     * 查询酒店列表
     */
    @ApiOperation("查询酒店列表")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Hotels hotels)
    {
        startPage();
        List<Hotels> list = hotelsService.selectHotelsList(hotels);
        return getDataTable(list);
    }

    /**
     * 导出酒店列表
     */
    @ApiOperation("导出酒店列表")
    @Anonymous
    @PostMapping("/export")
    public void export(HttpServletResponse response, Hotels hotels)
    {
        List<Hotels> list = hotelsService.selectHotelsList(hotels);
        ExcelUtil<Hotels> util = new ExcelUtil<Hotels>(Hotels.class);
        util.exportExcel(response, list, "酒店数据");
    }

    /**
     * 获取酒店详细信息
     */
    @ApiOperation("获取酒店详细信息")
    @Anonymous
    @GetMapping(value = "/{hotelId}")
    public AjaxResult getInfo(@PathVariable("hotelId") Long hotelId)
    {
        return success(hotelsService.selectHotelsByHotelId(hotelId));
    }

    /**
     * 新增酒店
     */
    @ApiOperation("新增酒店")
    @Anonymous
    @PostMapping
    public AjaxResult add(@RequestBody Hotels hotels)
    {
        return toAjax(hotelsService.save(hotels));
    }

    /**
     * 修改酒店
     */
    @Anonymous
    @ApiOperation("修改酒店")
    @PutMapping
    public AjaxResult edit(@RequestBody Hotels hotels)
    {
        return toAjax(hotelsService.updateById(hotels));
    }

    /**
     * 删除酒店
     */
    @ApiOperation("删除酒店")
    @Anonymous
	@DeleteMapping("/{hotelIds}")
    public AjaxResult remove(@PathVariable Long[] hotelIds)
    {
        return toAjax(hotelsService.removeByIds(Arrays.asList(hotelIds)));
    }

    /**
     * 查询酒店hotel_id和hotel_name
     */
    @ApiOperation("查询酒店hotel_id和hotel_name")
    @Anonymous
    @GetMapping("/selectHotelIdAndName")
    public AjaxResult selectHotelIdAndName()
    {

        return AjaxResult.success(hotelsService.selectHotelIdAndName());
    }


}
